package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.ShopInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.ShopInfoBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class ShopAdapter extends BaseAdapter<ShopInfoBean> {

    public ShopAdapter(Context context, List<ShopInfoBean> items, int layoutResource){
        super(context, items, layoutResource);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        ShopInfoViewHolder viewHolder = new ShopInfoViewHolder(itemView);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ShopInfoViewHolder viewHolder=(ShopInfoViewHolder) holder;
        ShopInfoBean shopInfoBean=items.get(position);


        final String shopname = shopInfoBean.getShop_name();
        final String intro = shopInfoBean.getShop_intro();
        final String shopid = shopInfoBean.getShop_id();
        final String img = Service.BASE_URL+"flower_impression/public/uploads/"+shopInfoBean.getShop_photo();
        final String time = shopInfoBean.getShop_opentime()+"-"+shopInfoBean.getShop_closetime();
        final String address = shopInfoBean.getShop_province()+shopInfoBean.getShop_city()+ shopInfoBean.getShop_address();


        viewHolder.shopitem_name.setText(shopname);
        viewHolder.shopitem_intro.setText(intro);
        viewHolder.shopitem_address.setText(address);

       ;
        viewHolder.shopitem_time.setText("营业时间："+time);

        Picasso.with(context).load(img).into(viewHolder.shopitem_img);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, ShopInfoActivity.class);
                    intent.putExtra("shopid",shopid);
                    context.startActivity(intent);
                }
        });
   }

}
